﻿using System;
using System.Net;

namespace CarbonKit.Core.Silverlight3.Extensions {
    using System.Reflection;

    public static class EnumerationExtensions {
        public static string Distinct<T>(this Enum enumerationValue) {
            if (enumerationValue == null) {
                throw new ArgumentException("enumerationValue");
            }

            string description = enumerationValue.ToString();
            FieldInfo fieldInfo = enumerationValue.GetType().GetField(description);
            var attributes = (EnumDescriptorAttribute[])fieldInfo.GetCustomAttributes(typeof(EnumDescriptorAttribute), false);
            if (attributes.Length > 0) {
                description = attributes[0].Description;
            }

            return description;
        }
    }
}
